<template>
  <div>
    <MyHeader></MyHeader>
    <SecHeader></SecHeader>
    <div>
      <h2 style="padding-left: 20px;padding-right: 20px">{{ article.title }}</h2>
      <span style="padding-left: 20px">{{ article.created_time }}</span>
      <span v-if="article.type==='national'" style="padding-left: 10px">央视新闻</span>
      <span v-if="article.type!='national'">社区新闻部</span>
    </div>
    <van-divider></van-divider>
    <p v-html="this.article.content" style="padding-left: 10px; padding-right: 10px"></p>
  </div>

</template>

<script>
import SecHeader from "../../components/SecHeader.vue";
import Home from "../Home.vue";
import MyHeader from "../../components/common/MyHeader.vue";

export default {
  name: "Article",
  components: {MyHeader, SecHeader},

  data() {
    return {
      article: {},
    }
  },

  methods: {
    getArticle(nid) {
      this.axios({
        method: "get",
        url: "/news/getNewsById/" + nid,
      }).then(resp => {
        if (resp) {
          if (resp.data.code == 200) {
            this.article = resp.data.data
            this.article.created_time = resp.data.data.created_time.split("T")[0]

            // console.log(this.article)


          }
        }
      })
    }
  },

  created() {
    //注意是route  不是router  接收路由过来的参数
    const nid = this.$route.params.nid
    this.getArticle(nid)

  }
}
</script>

<style scoped>
.van-divider {
  border-color: #065de1;
}
</style>
